package burp;

import beans.ErrorPayload;
import sqlInject.SqlInjectCheckImpl;
import threadManger.ThreadManager;
import ui.MainUi;
import ui.Model;
import ui.UI2;
import util.BurpCallbacks;
import validate.Validate;
import javax.swing.*;
import java.io.PrintWriter;

/**
 * Created by shuaidong on 2017/6/23.
 */
public class BurpExtender implements IHttpListener,IExtensionStateListener{

    public PrintWriter stdout;

    public IExtensionHelpers helpers;

    private static IBurpExtenderCallbacks callbacks;



    public BurpExtender() {
    }


    public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks) {
        this.stdout = new PrintWriter(callbacks.getStdout(),true);
        BurpExtender.callbacks = callbacks;
        this.helpers = callbacks.getHelpers();
        BurpCallbacks burpCallbacks = new BurpCallbacks(callbacks,stdout);

       // callbacks.registerContextMenuFactory(new SqlMenuContextFactory());
        ExtenderCallbacks extenderCallbacks = new ExtenderCallbacks();
        extenderCallbacks.init(callbacks);
        callbacks.setExtensionName("sqlinjectCheck by td");

         SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                /*MainUi mainUi = new MainUi(callbacks);
                mainUi.getUI();
*/
                UI2 ui2 = new UI2(callbacks);
                ui2.getUI();
                callbacks.registerContextMenuFactory(new SnifferContextMenuFactory(helpers,stdout));
                callbacks.registerHttpListener(BurpExtender.this);
                ScannerInsertPointProvider pointProvider = new ScannerInsertPointProvider(callbacks,stdout);
                callbacks.registerScannerInsertionPointProvider(pointProvider);
                callbacks.registerScannerCheck(new SqlScannerCheck(stdout,callbacks,new SqlInjectCheckImpl(callbacks,stdout,pointProvider),new Validate(helpers),pointProvider));




            }
        });


    }


    @Override
    public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequestResponse messageInfo) {


    }



    @Override
    public void extensionUnloaded() {
        ThreadManager.shutdownNow();


    }


}
